import Vue from 'vue'
import Vuex from 'vuex';
import svcInvoke from '@/common/vendor/asocer/svcinvoke.js';
import trade from '@/common/store/trade.js';
Vue.use(Vuex)
console.log(localStorage.getItem('tishi'))
export default new Vuex.Store({
  modules: {
    trade
  },
  state: {
    lineY: '',
    charbarData: {},
    userInfo : {},
    apiToken : '',
    stterHtml:{},
    zijinSet: {
      keyong: 0,
      quanyi: 0,
      fudong: 0,
      fengxiandu: 0
    },
    setting: {
      isTanc: localStorage.getItem('isTanc') == null ? '1': localStorage.getItem('isTanc'),
      checkedCities: localStorage.getItem('jiaoyi')  == null ? [1,2,3]:JSON.parse(localStorage.getItem('jiaoyi')),
      tishi:  localStorage.getItem('tishi') == null ? '1': localStorage.getItem('tishi'),
    },
    boxData: {},
    xuXianData: [], // 虚线显示数据
    Color: '',
    loginbrn:'',/* 控制站点开关 */
    bottomlist:'',/* 底部登录 */
    navtopheight:'',/* 分隔面板高度 */
    changecolor:null,/* 主题颜色 */
    isinclass:null,/* 控制左侧面板显示 */
    alertborder:null,/* 控制止盈止损提示框 */
    hoidlist:null/* 选中订单信息 */,
    klinetab: true,/*控制k线显示面板*/
    klinetime: null,/* k线周期 */
    newbuy:null,/* 委托订单买入卖出 */
    xitongnews:null,/* 系统消息 */
    tablistcode:{},/* 当前页面的code码 */
  },
  mutations: {
    setSetting(state, data) {
      localStorage.setItem('jiaoyi', JSON.stringify(data.checkedCities) )
      localStorage.setItem('isTanc', data.isTanc)
      localStorage.setItem('tishi', data.tishi)
      
      state.setting = data
    },
    setXuXianData(state, data) {
      state.xuXianData = data
    },
    setColor(state, data) {
      state.Color = data
    },
    setCharBarData(state, data) {
      state.charbarData = data
    },
    showBoxData(state, data) {
      state.boxData = data
    },
    drawLine(state, lineY) {
      state['lineY'] = lineY
    },
    set(state, payload) {
      for (var key in payload) {
        if (payload.hasOwnProperty(key)) state[key] = payload[key]
      }
      // console.log(state,'state2');
    },
    del(state, key) {
      delete state[key]
    },
    reset(state) {
      for (let key in state) {
        delete state[key]
      }
    },
    // set_bottomlist(state, item) {
    // 	state.bottomlist = item;
    // },
  },
  actions: {
    async resetXuxian({commit}, symbol) {
        if (symbol == '') {
          commit('setXuXianData', [])
        } else {
          Vue.prototype.$post('order/linedata', {
            contract: symbol
          }).then( res => {
            commit('setXuXianData', res.data)
          })
        }
        
    },
    // myinfo({ commit, dispatch }){
    // 	svcInvoke.get('myinfo').then(res=>{
    // 		if(res.code=='0'){
    // 			commit('set',{userInfo:res.data});
    // 		}
    // 	})
    // },
    // setterHtml({ commit, dispatch }){
    // 	svcInvoke.get('setter_html').then(res=>{
    // 		if(res.code=='0'){
    // 			var data = {};
    // 			for(let i = 0;i<res.data.length;i++){
    // 				data[res.data[i].code] = res.data[i];
    // 			}
    // 			commit('set',{stterHtml:data});
    // 		}
    // 	})
    // }
  }
})
